<template>
  <div>
    <script :id=id type="text/plain"></script>
  </div>
</template>
<script>
  export default {
    name: 'UE',
    data() {
      return {
        editor: null
      }
    },
    props: {
      defaultMsg: {
        type: String
      },
      config: {
        type: Object
      },
      id: {
        type: String
      },
      value: {
        type: String
      }
    },
    mounted() {
      const _this = this
      this.editor = window.UE.getEditor(this.id, this.config) // 初始化UE
      this.editor.addListener('ready', function() {
        _this.editor.setContent(_this.defaultMsg) // 确保UE加载完成后，放入内容。
      })
      console.log('上传这堆错误不用理会，上传接口需自行开发配置')
    },
    watch: {
      defaultMsg: function() {
        this.editor = window.UE.getEditor(this.id, this.config) // 初始化UE
        this.editor.setContent(this.defaultMsg)
      }
    },
    methods: {
      getUEContent() { // 获取内容方法
        return this.editor.getContent()
      },
      getUEContentTxt() { // 获取纯文本内容方法
        return this.editor.getContentTxt()
      },
      setContents() {
        this.editor.setContent(this.defaultMsg)
      },
      destroy() {
        this.editor.destroy()
      }
    },
    destroyed() {
      this.destroy()
    }
  }
</script>